package com.gdut.multiusercommunicationsystem.controller;

import com.gdut.multiusercommunicationsystem.model.Message;
import com.gdut.multiusercommunicationsystem.mapper.MessageMapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {
    @Resource
    public MessageMapper messageMapper;
    @GetMapping("/message")
    @ResponseBody
    public Object getMessages(int sessionId){
        List<Message> messages=messageMapper.getMessagesBySession(sessionId);
        Collections.reverse(messages);
        return messages;
    }
}
